<?php
namespace app\api\controller;
include "../extend/tbk/TopSdk.php";

use app\common\controller\Api;
/**
 * 淘宝客
 */
class Tbk extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    /**
     * 淘宝客-推广者-物料精选
     * https://open.taobao.com/api.htm?docId=62201&docType=2&scopeId=27939#commponParams
     * @param $materialId
     */
    public function recommend($materialId)
    {
        $c = new \TopClient;
        $c->appkey = config('tbk.AppKey');
        $c->secretKey = config('tbk.AppSecret');
        $req = new \TbkDgMaterialRecommendRequest;
        $req->setMaterialId($materialId);
        $req->setAdzoneId(config('tbk.AdzoneId'));
        $resp = $c->execute($req);
        $this->success('返回成功', $resp);
    }

    /**
     * 淘宝客-推广者-物料id列表查询
     * https://open.taobao.com/api.htm?docId=64333&docType=2&scopeId=27939#commponParams
     */
    public function material()
    {
        $c = new \TopClient;
        $c->appkey = config('tbk.AppKey');
        $c->secretKey = config('tbk.AppSecret');
        $req = new \TbkOptimusTouMaterialIdsGetRequest;
        $material_query = new \MaterialQuery;
        $material_query->page_no="1";
        $material_query->subject="1";
        $material_query->material_type="1";
        $material_query->page_size="20";
        $req->setMaterialQuery(json_encode($material_query));
        $resp = $c->execute($req);
        $this->success('返回成功', $resp);
    }
    /**
     * 淘宝客-推广者-新用户订单明细查询
     * https://open.taobao.com/api.htm?docId=33892&docType=2&scopeId=16188#requestExample
     */
    public function order()
    {
        $c = new \TopClient;
        $c->appkey = config('tbk.AppKey');
        $c->secretKey = config('tbk.AppSecret');
        $req = new \TbkDgNewuserOrderGetRequest;
        $req->setAdzoneId(config('tbk.AdzoneId'));
//        $req->setActivityId("119013_2");
        $resp = $c->execute($req);
        $this->success('返回成功', $resp);
    }
}
